import { defineStore } from 'pinia'

const useUserStore = defineStore('user', {
     // 推荐函数：避免服务端渲染导致的数据状态污染
    // 箭头函数：为了更好的 TS 类型推导
    state: () => {
        return {
            token: '',
            userId: ''
        }
    },
    actions: {
        setToken(payload:string) {
            this.token = payload
            localStorage.setItem('token', payload)
        },
        setUserId(payload:string) {
            this.userId = payload
            localStorage.setItem('userId', payload)
        },
        removeToken() {
            this.token = ''
            this.userId = ''
        }
    }
})


export default useUserStore
